﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace RedSand.Site
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            //custom

            routes.MapRoute(
               "category list",
               "category/list/{parent}/{level}",
               new { controller = "category", action = "list", level = 0, parent = 0 }
            );
            
            routes.MapRoute(
               "category create",
               "category/create/{count}/{parent}/{level}",
               new { controller = "category", action = "create", count = UrlParameter.Optional, parent = 0, level = 0 }
            );
            routes.MapRoute(
               "category create pro",
               "category/createproperty/{count}/{category}",
               new { controller = "category", action = "createproperty", count = UrlParameter.Optional, category = 0 }
            );
            routes.MapRoute(
               "category edit",
               "category/edit/{id}/{count}/{level}",
               new { controller = "category", action = "edit", id = UrlParameter.Optional, count = UrlParameter.Optional, level = 0 }
            );
            routes.MapRoute(
               "category edit pro",
               "category/editproperty/{id}/{count}/{category}",
               new { controller = "category", action = "editproperty", id = UrlParameter.Optional, count = UrlParameter.Optional, category = 0 }
            );
            routes.MapRoute(
               "category delete",
               "category/delete/{id}/{parent}/{level}",
               new { controller = "category", action = "delete", id = UrlParameter.Optional, parent = 0, level = 0 }
            );
            //product
            routes.MapRoute(
               "product ",
               "product/{alias}",
               new { controller = "product", action = "products", alias = UrlParameter.Optional }
            );
            
            //global
            routes.MapRoute(
               "Details Support",
               "support/details",
               new { controller = "Support", action = "GetInfoById" }
           );
            routes.MapRoute(
               "Faq, page",
               "Faq/ListFaq/{page}",
               new { controller = "Faq", action = "ListFaq", page = UrlParameter.Optional }
           );
            routes.MapRoute(
                "by keyword, page",
                "{controller}/search/{keyword}/{page}",
                new { controller = "news", action = "search", page = UrlParameter.Optional, keyword = UrlParameter.Optional }
            );
            routes.MapRoute(
                "by category, page",
                "{Controller}/category/{CategoryId}/{page}",
                new { controller = "news", action = "search", CategoryId = UrlParameter.Optional, page = UrlParameter.Optional }
            );

            routes.MapRoute(
                "List Service",
                "{Controller}/details/",
                new { Controller = "service", action = "listservice"}
            );

            routes.MapRoute(
               "by type",
               "{Controller}/details/{alias}",
               new { Controller = "news", action = "Details", alias = UrlParameter.Optional }
           );

            routes.MapRoute(
                "by index page",
                "{Controller}/{page}",
                new { controller = "news", action = "index", page = UrlParameter.Optional },
                new { controller = @"news|product|schedule", page = @"\d+|pageindex" }
            );

            routes.MapRoute(
                "by id title",
                "{controller}/{action}/{id}/{title}",
                new { controller = "home", action = "index", id = UrlParameter.Optional, title = UrlParameter.Optional }
            );
            routes.MapRoute(
                "by id",
                "{controller}/{action}/{id}",
                new { controller = "home", action = "index", id = UrlParameter.Optional }
            );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    }
}